# ------------------------------------------------------------------------------------------------
### Generate Figure 5: Map of LGBTQ-free zones by wave
# ------------------------------------------------------------------------------------------------

# Load data
load("../data/processed/LGBTQ_election_data.Rda")

# Define color scheme and labels for the map
map_colors <- c("transparent", "#D9534F", "grey")
map_labels <- c(
  "No resolution", 
  "Anti-LGBTQ+ resolution \n before 2019 parl. election", 
  "Anti-LGBTQ+ resolution \n after 2019 parl. election"
)

# Load and process municipality boundaries
PL_gmina <- gisco_get_lau(country = "PL", year="2020") %>%
  mutate(id = paste0(substr(LAU_ID, 5, 6), substr(LAU_ID, 10, nchar(LAU_ID)))) %>%
  left_join(
    LGBTQ_election_data %>% 
      select(id, wave_id) %>% 
      unique(), 
    by = "id"
  ) 

# Generate map
ggplot(PL_gmina) +
  geom_sf(aes(fill = wave_id)) +
  scale_fill_manual(
    values = map_colors,
    labels = map_labels,
    name = " "
  ) +
  theme_map() +
  theme(
    legend.position = "bottom",
    legend.justification = c(.5),
    text = element_text(size = 23)
  )

# Save the plot
ggsave("../output/plots/figure5.pdf", width = 14, height = 10, dpi = 600)

